package com.xieyong.leetcode;

public class Leetcode3307 {
    public static void main(String[] args) {
        Leetcode3307 leetcode = new Leetcode3307();
        int k = 5;
        int[] options = {0,0,0};
        char c = leetcode.kthCharacter(k, options);
        System.out.println(c);

    }


    public char kthCharacter(long k, int[] operations) {
        if(k==1) return 'a';
        int step = (int) Math.ceil(Math.log(k) / Math.log(2));
        char c = kthCharacter(k-(long)Math.pow(2, step-1), operations);
        if(operations[step-1] == 1) return (char)((c-'a'+1)%26+('a'-0));
        return c;
    }


//    public char kthCharacter(int k) {
//        StringBuilder sb = new StringBuilder();
//        sb.append('a');
//        while(sb.length() < k) {
//            StringBuilder newstr = new StringBuilder();
//            for(int i = 0; i < sb.length(); i++) {
//                newstr.append((char) (sb.charAt(i) + 1));
//
//            }
//            sb.append(newstr);
//        }
//        return sb.charAt(k - 1);
//    }
}
